package ceet.ac.cn.dao;

import java.sql.Connection;
import java.sql.DriverManager;
/**
 * 连接数据库
 * @author 画船听雨眠
 *
 */
public class DbHelper {
    private static String url = "jdbc:mysql://203.195.140.20:3306/css_db";  //数据库地址
    private static String userName = "root";  //数据库用户名
    private static String passWord = "Chui@2018";  //数据库密码
//    private static String url = "jdbc:mysql://localhost:3306/test";  //数据库地址
//    private static String userName = "root";  //数据库用户名
//    private static String passWord = "why";  //数据库密码
    private static Connection conn = null;
    
    private DbHelper(){
        
    }
    
    public static Connection getConnection(){
        if(null == conn){
            try {
//                Class.forName("com.mysql.cj.jdbc.Driver");//mysql8.0.12版本调用的驱动
//                conn = DriverManager.getConnection(url + "?useSSL=false&serverTimezone=UTC",userName,passWord); 
                //Url="jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection(url, userName, passWord);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return conn;
    }
    
    public static void main(String[] args) {  //测试数据库是否连通
        System.err.println(getConnection());
    }
}